package com.pickgliss.geom
{
	import flash.geom.Rectangle;
	/**
	 * 一个根据外部的宽高来确定内部矩形宽高的类
	 * 
	 * @author Herman
	 * 
	 */	
	public class InnerRectangle
	{
			
		public function InnerRectangle(para1:int,para2:int,para3:int,para4:int,lockDirection:int = 0)
		{
			this.para1 = para1;
			this.para2 = para2;
			this.para3 = para3;
			this.para4 = para4;
			this.lockDirection = lockDirection;
		}

		public var lockDirection:int;
		public var para1:int;
		public var para2:int;
		public var para3:int;
		public var para4:int;
		private var _outerHeight:int;
		private var _outerWidth:int;
		private var _resultRect:Rectangle;
		/**
		 * 
		 * 判断两个InnerRectangle是否相等
		 * 
		 * @param innerRect 目标对象
		 * @return 是否相等
		 * 
		 * 
		 */		
		public function equals(innerRect:InnerRectangle):Boolean
		{
			if(innerRect == null)return false;
			return para4 == innerRect.para4 &&
				para1 == innerRect.para1 &&
				lockDirection == innerRect.lockDirection &&
				para2 == innerRect.para2 &&
				para3 == innerRect.para3
		}
		/**
		 * 
		 * @param outerWidth 相对的宽度
		 * @param outerHeight 相对的高度
		 * @return 显示区域的矩形
		 * 
		 */		
		public function getInnerRect(outerWidth:int,outerHeight:int):Rectangle
		{
			_outerWidth = outerWidth;
			_outerHeight = outerHeight;
			return calculateCurrent();
		}
		
		private function calculateCurrent():Rectangle
		{
			var resultRect:Rectangle = new Rectangle();
			if(lockDirection == LockDirectionTypes.UNLOCK)
			{
				resultRect.x = para1;
				resultRect.y = para3;
				resultRect.width = _outerWidth - para1 - para2;
				resultRect.height = _outerHeight - para3 - para4;
			}else if(lockDirection == LockDirectionTypes.LOCK_T)
			{
				resultRect.x = para1;
				resultRect.y = para3;
				resultRect.width = _outerWidth - para1 - para2;
				resultRect.height = para4;
			}else if(lockDirection == LockDirectionTypes.LOCK_L)
			{
				resultRect.x = para1;
				resultRect.y = para3;
				resultRect.width = para2;
				resultRect.height = _outerHeight - para3 - para4;
			}else if(lockDirection == LockDirectionTypes.LOCK_R)
			{
				resultRect.x =_outerWidth -  para1 - para2;
				resultRect.y = para3;
				resultRect.width = para1;
				resultRect.height = _outerHeight - para3 - para4;
			}else if(lockDirection == LockDirectionTypes.LOCK_B)
			{
				resultRect.x = para1;
				resultRect.y = _outerHeight -  para3 - para4;
				resultRect.width = _outerWidth - para1 - para2;
				resultRect.height = para3;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_T)
			{
				resultRect.x = (_outerWidth - para1)/2 +para4;
				resultRect.y = para3;
				resultRect.width = para1;
				resultRect.height = para2;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_B)
			{
				resultRect.x = (_outerWidth - para1)/2 +para3;
				resultRect.y = _outerHeight - para4 - para2;
				resultRect.width = para1;
				resultRect.height = para2;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_L)
			{
				resultRect.x = para1;
				resultRect.y = (_outerHeight - para4)/2+para2;
				resultRect.width = para3;
				resultRect.height = para4;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_R)
			{
				resultRect.x = _outerWidth - para2 - para3;
				resultRect.y = (_outerHeight - para3)/2 + para1;
				resultRect.width = para3;
				resultRect.height = para4;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_TL)
			{
				resultRect.x = para1;
				resultRect.y = para3;
				resultRect.width = para2;
				resultRect.height = para4;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_TR)
			{
				resultRect.x = _outerWidth - para1 - para2;
				resultRect.y = para3;
				resultRect.width = para1;
				resultRect.height = para4;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_BL)
			{
				resultRect.x = para1;
				resultRect.y = _outerHeight - para4 - para3;
				resultRect.width = para2;
				resultRect.height = para3;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_BR)
			{
				resultRect.x = _outerWidth - para1 - para2;
				resultRect.y = _outerHeight - para4 - para3;
				resultRect.width = para1;
				resultRect.height = para3;
			}else if(lockDirection == LockDirectionTypes.UNLOCK_OUTSIDE)
			{
				resultRect.x = -para1;
				resultRect.y = -para3;
				resultRect.width = _outerWidth + para1 + para2;
				resultRect.height = _outerHeight + para4 + para3;
			}else if(lockDirection == LockDirectionTypes.NO_SCALE_C)
			{
				resultRect.x = (_outerWidth - para2)/2+para1;
				resultRect.y = (_outerHeight - para4)/2+para3;
				resultRect.width = para2;
				resultRect.height = para4;
			}else if(lockDirection == LockDirectionTypes.LOCK_TL)
			{
				resultRect.x = para1;
				resultRect.y = para2;
				resultRect.width = _outerWidth - para3;
				resultRect.height = _outerHeight - para4;
			}else if(lockDirection == LockDirectionTypes.LOCK_OUTER_DOWN)
			{
				resultRect.x = para1;
				resultRect.y = para2;
				resultRect.width = _outerWidth - para3;
				resultRect.height = para4;
			}
			
			return resultRect;
		}
	}
}